/* Copyright (c) 2019 Data.Co.Ltd. All rights reserved. */
package info.peigen.hotpot.component.open.api.facade;

import com.google.common.collect.Maps;
import info.peigen.hotpot.common.core.result.ResultBase;
import info.peigen.hotpot.common.service.base.DomainService;
import info.peigen.hotpot.common.service.base.ServiceFacade;
import info.peigen.hotpot.component.open.api.facade.order.OpenApiOrder;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;

import java.io.Serial;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Map;

/**
 * <b>(OpenApiServiceContext)</b>
 * OpenApi服务的上下文,可以在Service层与DomainService层使用
 *
 * @author Ming
 * @version 1.0.0
 * @since 2019/05/18
 */
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@Accessors(chain = true)
public class OpenApiServiceContext<ORDER extends OpenApiOrder, RESULT extends ResultBase> implements Serializable {
    @Serial
    private static final long serialVersionUID = -7996369895294878828L;

    /** 当前数据库时间戳 <code>currentTimestamp</code> */
    Timestamp currentTimestamp;

    /** 请求参数 <code>order</code> */
    ORDER order;

    /** 应答返回 <code>result</code> */
    RESULT result;

    /** 其他可能需要传输的领域对象 <code>domain</code> */
    Api domain;

    /** 领域服务 */
    DomainService domainService;
    /** 在开启Mock的情况下需要Mock掉的服务可以放到这里 */
    DomainService domainMockService;

    /** Service层的Facade,可以认为是依赖的其他Service */
    ServiceFacade serviceFacade;
    /** 在开启Mock的情况下需要Mock掉的服务可以放到这里 */
    ServiceFacade mockServiceFacade;

    String channelCode;

    /** 临时用于传递entity */
    Object object;

    /** 扩展参数 */
    @Builder.Default
    Map<String, Object> extend = Maps.newHashMap();

    public OpenApiServiceContext(ORDER order, RESULT result) {
        this.order = order;
        this.result = result;
    }

    public OpenApiServiceContext(ORDER order, RESULT result, ServiceFacade serviceFacade) {
        this.order = order;
        this.result = result;
        this.serviceFacade = serviceFacade;
    }

    public OpenApiServiceContext(ORDER order, RESULT result, DomainService domainService) {
        this.order = order;
        this.result = result;
        this.domainService = domainService;
    }
}